<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport" phonenumber="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理
            <small>预约订单管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约订单管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <template>
                    <el-date-picker
                            v-model="value2"
                            type="datetimerange"
                            :picker-options="pickerOptions"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            align="right">
                    </el-date-picker>
                </template>

                <el-select v-model="orderType" placeholder="预约类型">
                    <el-option
                            v-for="item in orderType_options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"></el-option>
                </el-select>

                <el-select v-model="orderStatus" placeholder="预约状态">
                    <el-option
                            v-for="item in orderStatus_options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>

                <el-input
                        placeholder="姓名/手机号"
                        v-model="pagination.queryString"
                        style="width: 200px;"
                        class="filter-item"
                        @keyup.enter.native="handleFilter" >
                </el-input>
                <el-button @click="findPages()" class="dalfBut">查询</el-button>
                    <el-button type="primary" class="butT" @click="handleCreate()">预约</el-button>
                    <el-button type="primary" class="butT" @click="Clear()">清除</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="name" label="会员姓名" align="center"></el-table-column>
                <el-table-column prop="phonenumber" label="电话号码" align="center"></el-table-column>
                <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="orderStatus" label="预约状态" align="center">
                    <template slot-scope="scope">
                        <el-switch
                                v-model="scope.row.orderStatus"
                                active-color="#ff4949"
                                inactive-color="#13ce66"
                                active-value="未到诊"
                                inactive-value="已到诊"
                                active-text ="未到诊"
                                inactive-text = "已到诊"
                                @change=change(scope.row)>
                        </el-switch>
                    </template>
                </el-table-column>
                <el-table-column prop="sname" label="套餐名称" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" ref="dataAddForm" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="会员姓名" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="电话号码" prop="phoneNumber">
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="预约日期">
                                                <el-date-picker
                                                        v-model="formData.orderDate" prop="orderDate"
                                                        type="date"
                                                        placeholder="选择日期"
                                                        value-format="yyyy-MM-dd">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>套餐编码</th>
                                            <th>套餐名称</th>
                                            <th>套餐说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="setmealIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td><label :for="c.id">{{c.code}}</label></td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑预约" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" ref="dataAddForm" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="会员姓名" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                             <el-form-item label="预约日期" prop="orderDate">
                                                 <el-date-picker
                                                         v-model="formData.orderDate"
                                                         type="date"
                                                         placeholder="选择日期"
                                                         value-format="yyyy-MM-dd">
                                                 </el-date-picker>
                                             </el-form-item>

                                        </el-col>
                                    </el-row>
                                    <el-row>

                                        <el-col :span="12">
                                            <el-form-item label="预约类型">
                                                <el-select v-model="formData.orderType">
                                                    <el-option label="电话预约" value="电话预约"></el-option>
                                                    <el-option label="微信预约" value="微信预约"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="预约状态">
                                                <el-select v-model="formData.orderStatus">
                                                    <el-option label="已到诊" value="1"></el-option>
                                                    <el-option label="未到诊" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="订单信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>套餐编码</th>
                                            <th>套餐名称</th>
                                            <th>套餐说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="setmealIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td><label :for="c.id">{{c.code}}</label></td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>

<script>

    var vue = new Vue({

        el: '#app',
        data: {
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 5,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            tableData:[],//新增和编辑表单中对应的检查项列表数据
            setmealIds:[],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            orderType: null,//条件查询预约类型
            orderStatus: null,//条件查询预约状态
            orderDate: null,
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            orderType_options: [{//预约类型下拉条属性
                label: '请选择'
            },{
                value: '微信预约',
                label: '微信预约'
            }, {
                value: '电话预约',
                label: '电话预约'
            }],
            orderStatus_options: [{//预约状态下拉属性条
                label: '请选择'
            },{
                value: '未到诊',
                label: '未到诊'
            }, {
                value: '已到诊',
                label: '已到诊'
            }],
            rules: {//校验规则
                code: [{required: true, message: '项目编码为必填项', trigger: 'blur'}],
                name: [{required: true, message: '项目名称为必填项', trigger: 'blur'}]
            }
        },


        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage()
        },
        methods: {
            //点击已经预约
            change(row){
                axios.post("/ReservationOrderManagemen/setOrderStatus.do?id=" + row.id).then((res)=>{
                    if (res.data.flag) {
                    this.$message.success(res.data.message);
                    this.findPages();
                } else {
                    this.$message.error(res.data.message);
                }
            });
            },
            //清除按钮
            Clear() {
                //点击按钮重置查询框的属性
                this.orderDate = [],//条件查询时间选择器
                    this.orderType = '',//条件查询预约类型
                    this.orderStatus = '',//条件查询预约状态
                    this.pagination.queryString = ''//插件查询会员名称/手机号
            },
            //编辑
            handleEdit() {
                axios.post("/ReservationOrderManagemen/edit.do?setmealIds=" + this.setmealIds, this.formData).then((res) => {
                    this.dialogFormVisible4Edit = false;
                    if (res.data.flag) {
                    this.$message.success(res.data.message);
                } else {
                    this.$message.error(res.data.message);
                }
            }).finally(() => {
                    this.findPages();
            });
            },
            //添加
            handleAdd() {
                axios.post("/ReservationOrderManagemen/add.do?setmealIds="+this.setmealIds,this.formData).then(function (res) {
                    if (res.data.flag){
                        vue.$message({
                            type:'success',
                            message:res.data.message
                        })
                    } else {
                        vue.$message.error(res.data.message)
                    }
                }).finally(function () {
                    vue.dialogFormVisible=false
                    vue.findPage()
                })
            },

            //分页查询
            findPages() {
                this.pagination.currentPage = 1
                this.findPage()
            },
            findPage() {
                axios.post("/ReservationOrderManagemen/conditionFindSAll.do", this.pagination).then(function (res) {
                    if (res.data.total == 0) {
                        vue.$message.error("您输入有误,请重新输入")
                    } else {
                        vue.pagination.total = res.data.total
                        vue.dataList = res.data.rows
                    }
                })
            },
            // 重置表单
            resetForm() {
            },

            // 弹出添加窗口
            handleCreate() {
                this.activeName = 'first'
                this.setmealIds=[]
                this.formData = {}
                this.dialogFormVisible=true
                axios.post("/ReservationOrderManagemen/findAll.do").then(function (res) {
                    vue.tableData = res.data
                })
            },
            // 弹出编辑窗口
            handleUpdate(row) {
                this.formData = row
                this.dialogFormVisible4Edit = true
                vue.setmealIds=[]
                this.formData = row
                axios.post("/ReservationOrderManagemen/findAll.do").then(function (res) {
                    vue.tableData = res.data
                })
                /*axios.post("/ReservationOrderManagemen/findById.do?id="+row.setmeal_id).then(function (res) {
                    for (var i = 0; i <res.data.data.length ; i++) {
                        vue.setmealIds.push(res.data.data[i])
                    }
                })*/
                vue.setmealIds.push(row.setmeal_id)
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            // 删除
            handleDelete(row) {
                this.$confirm("此操作将永久删除该文件, 是否继续?","提示",{
                    type:'warning'
                }).then(()=>{
                    axios.post("/ReservationOrderManagemen/delete.do?id="+row.id).then(function (res) {
                    if (res.data.flag){
                        vue.$message({
                            type:'success',
                            message:res.data.message
                        })
                    }else {
                        vue.$message.error(res.data.message)
                    }
                }).finally(function () {
                    vue.findPage()
                })
            }).catch(function () {
                    vue.$message.error("谢谢你的手下留情")
                })
            }
        }
    })
</script>
</html>